﻿using System;
using Resonance.TrainNode.Contracts.Entities;

namespace Resonance.TrainNode.Services
{
	internal static class GlobalTrain
	{
		private static NodeInfo _Node;

		static GlobalTrain()
		{
			_Node = new NodeInfo();
			_Node.CoreCount = System.Environment.ProcessorCount;
			_Node.Description = System.Environment.MachineName;
			_Node.UniqueName = System.Environment.MachineName;
		}

		internal static NodeInfo Node
		{
			get
			{
				lock (_Node)
				{
					return _Node.Clone();
				}
			}
			set
			{
				lock (_Node)
				{
					if (value == null)
					{
						throw new ArgumentException("NodeInfo object null");
					}
					_Node = value.Clone();
				}
			}
		}

		private static NodeInfo Clone(this NodeInfo src)
		{
			NodeInfo dest = new NodeInfo();
			dest.CoreCount = src.CoreCount;
			dest.Description = src.Description;
			dest.UniqueName = src.UniqueName;
			return dest;
		}
	}
}
